<?php

namespace addons\shopro\listener\api;

use addons\shopro\services\CategoryService;
use think\Exception;

class Api
{

    /**
     * 后台添加监听 切记注意监听清理
     * 使用方法  \think\Hook::listen('api_cache_after', $type); $type = CacheEnum::API_CATEGORY
     * @param $type
     * @return bool
     * @Author ycr <E-mail:yuncran@126.com>
     */
    public function apiCacheAfter($type)
    {
        try {

            return (new CategoryService())->clearCache($type);
        } catch (Exception $exception) {
            // 可以记录一下错误
            \think\Log::write('apiCache:' . json_encode($exception->getMessage()));
        }
    }
}